#ifndef	__BFX_REFDECODERBESTFITFALLBACK_H__
#define	__BFX_REFDECODERBESTFITFALLBACK_H__

namespace BFX
{

class REFDecoderReplacementFallback;

//////////////////////////////////////////////////////////////////////////////
// Represents a substitute output string that is emitted when the original input byte sequence cannot be decoded.
class REFDecoderReplacementFallbackBuffer: public REFDecoderFallbackBuffer
{
public:
	// Initializes / destorys a new instance of the DecoderReplacementFallbackBuffer class using the value of a DecoderReplacementFallback object. 
	REFDecoderReplacementFallbackBuffer(REFDecoderReplacementFallback* pFallback);
	virtual ~REFDecoderReplacementFallbackBuffer();

	// Prepares the fallback buffer to handle the specified input byte sequence.
	virtual bool Fallback(SequenceT<BYTE> bytesUnknown, int iOffset);
	// Retrieves the next character in the fallback buffer.
	virtual UCHAR GetNextChar();
	// Back up a character, move to the previous character position. 
	virtual bool MovePrevious();
	// Gets the number of characters in the replacement fallback buffer that remain to be processed.
	virtual int GetRemaining();

protected:
	UCHAR	m_chReplacement;
	int		m_nFallbackCount;
};

//////////////////////////////////////////////////////////////////////////////
// Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that cannot be converted to an output character.
// The fallback emits a user-specified replacement character instead of a decoded input byte sequence.
class REFDecoderReplacementFallback : public REFDecoderFallback
{
public:
	// Initializes / destorys a new instance of the DecoderReplacementFallback class. 
	REFDecoderReplacementFallback(UCHAR chReplacement);
	virtual ~REFDecoderReplacementFallback();

	// Creates a DecoderFallbackBuffer object that is initialized with the replacement character of this DecoderReplacementFallback object.
	virtual REFDecoderFallbackBuffer* CreateFallbackBuffer();
	// Returns number of our replacement characters.
	virtual int GetMaxCharCount() const
	{
		return 1;	// we have only 1 replacement character.
	}
	// Returns our replacement character.
	UCHAR GetReplacementChar() const
	{
		return m_chReplacement;
	}

protected:
	UCHAR	m_chReplacement;
};

}	//	namespace BFX

#endif	//	__BFX_REFDECODERBESTFITFALLBACK_H__
